package com.example.bbs.controller.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jiajiazi
 * @version 1.0
 * @date 2021/5/6 2:23
 */
@Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
        List<String> upatters = new ArrayList<>();
        upatters.add("/article/**");
        upatters.add("/ask/**");
        upatters.add("/user/**");
        upatters.add("/upload/**");
        upatters.add("/comment/**");
        List<String> uepatters = new ArrayList<>();
        uepatters.add("/article");
        uepatters.add("/article/select_by_id/**");
        uepatters.add("/article/update_support/**");
        uepatters.add("/article/select_by_tagid/**");
        uepatters.add("/ask");
        uepatters.add("/ask/detail2/**");
        uepatters.add("/comment/get**");
        registry.addInterceptor(new UserInterceptor()).addPathPatterns(upatters)
                .excludePathPatterns(uepatters);
        List<String> apatters = new ArrayList<>();
        apatters.add("/admin/**");
        List<String> aepatters = new ArrayList<>();
        aepatters.add("/admin");
        aepatters.add("/admin-tologin");
        aepatters.add("/admin/sweetalert/**");

        registry.addInterceptor(new AdminInterceptor()).addPathPatterns(apatters).excludePathPatterns(aepatters);
    }
}
